% Written by Dr R�mi Neveu. Any request to remi.neveu@isc.cnrs.fr. Any use must cite the article these analyses refer to
% GLM showing the results of figure 1B
ValueFolderTemp='Full path to where the output of the data extraction for journals is stored';
VecValueTime=[2];
VecValueFilter=[1];
for n5=1:size(VecValueTime,2)
    for n6=1:size(VecValueFilter,2)
        ValueTime=VecValueTime(1,n5);
        ValueFilter=VecValueFilter(1,n6);
        n1=32;
        if ValueTime>=1
            if ValueFilter==0
                ValueFile=['FileAnalysis' num2str(ValueTime) 'Journal' num2str(n1) '.mat'];
            else
                ValueFile=['FileAnalysis' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
            end
        else
            if ValueFilter==0
                ValueFile=['FileAnalysisJournal' num2str(n1) '.mat'];
            else
                ValueFile=['FileAnalysisFiltered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
            end
        end
        load([ValueFolderTemp ValueFile]);
        n2=1;
        TestTemp=0;
        while n2<=size(VecResultsArticle2,1)&&TestTemp==0
            if VecResultsArticle2(n2,4)>0
                TestTemp=1;
            end
            n2=n2+1;
        end
        VecValueTemp32=VecResultsArticle2(n2-1:end,:);
        VecValue2Temp32=VecResultsArticle1(n2-1:end,:);
        n1=33;
        if ValueTime>=1
            if ValueFilter==0
                ValueFile=['FileAnalysis' num2str(ValueTime) 'Journal' num2str(n1) '.mat'];
            else
                ValueFile=['FileAnalysis' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
            end
        else
            if ValueFilter==0
                ValueFile=['FileAnalysisJournal' num2str(n1) '.mat'];
            else
                ValueFile=['FileAnalysisFiltered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
            end
        end
        load([ValueFolderTemp ValueFile]);
        n2=1;
        TestTemp=0;
        while n2<=size(VecResultsArticle2,1)&&TestTemp==0
            if VecResultsArticle2(n2,4)>0
                TestTemp=1;
            end
            n2=n2+1;
        end
        VecValueTemp33=VecResultsArticle2(n2-1:end,:);
        VecValue2Temp33=VecResultsArticle1(n2-1:end,:);
        VecResults=[];
        VecResults2=[];
        for n1=1:33
            if n1~=32
                if ValueTime>=1
                    if ValueFilter==0
                        ValueFile=['FileAnalysis' num2str(ValueTime) 'Journal' num2str(n1) '.mat'];
                    else
                        ValueFile=['FileAnalysis' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
                    end
                else
                    if ValueFilter==0
                        ValueFile=['FileAnalysisJournal' num2str(n1) '.mat'];
                    else
                        ValueFile=['FileAnalysisFiltered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
                    end
                end
                ValueFileTemp=dir([ValueFolderTemp ValueFile]);
                load([ValueFolderTemp ValueFile]);
                n2=1;
                TestTemp=0;
                while n2<=size(VecResultsArticle2,1)&&TestTemp==0
                    if VecResultsArticle2(n2,4)>0
                        TestTemp=1;
                    end
                    n2=n2+1;
                end
                VecValueTemp=VecResultsArticle2(n2-1:end,:);
                VecValue2Temp=VecResultsArticle1(n2-1:end,:);
                if VecValueTemp(1,3)>0&&VecValue2Temp(1,3)>0
                    % Year of the luanch of the new journal-year before the year of the launch of the new journal
                    VecResults=[VecResults;VecValueTemp(1,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+1,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),1)/VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+1,1)/VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+1,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),1) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+1,1)+VecValueTemp(1,1) -size(VecValueTemp,1)+1];
                    if size(VecValueTemp,1)>1
                        % Year after the the year of the launch of a new journal-year before the year of the launch of the new journal
                        VecResults2=[VecResults2;VecValueTemp(2,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+2,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),1)/VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+2,1)/VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+2,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),1) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+2,1)+VecValueTemp(2,1) -size(VecValueTemp,1)+1];
                    end
                end
            end
        end
        [ValueResults,stats]=robustfit(VecResults(:,end),VecResults(:,7)-VecResults(:,6));
    end
end
% Fit over time of the difference in total number of original articles in Nature and the new journal between after launch and before launch
[ValueResults2,stats]=robustfit(VecResults(:,end),VecResults(:,3)+VecResults(:,1)-VecResults(:,2));
[ValueResults2,table,stats2]=anovan(VecResults(:,3)+VecResults(:,1)-VecResults(:,2),{VecResults(:,end)},'continuous',1,'model','full','display','off');
% Fit over time of the difference in total number of original articles with only new authors in Nature and the new journal between after launch and before launch
[ValueResults,stats]=robustfit(VecResults(:,end),VecResults(:,7)-VecResults(:,6));
[ValueResults,table,stats]=anovan(VecResults(:,7)-VecResults(:,6),{VecResults(:,end)},'continuous',1,'model','full','display','off');


